/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProjectModelView.java
 *
 * Created on 24.03.2010, 23:45:20
 */
package UI;

import Common.IProjectModel;
import ComponentsUI.IPrimitiveUI;
import Primitive.EPrimitiveType;
import Primitive.RectangleUI;
import Project.PrimitiveModelFactory;
import UI.Tree.DocumentNode;
import java.awt.event.MouseEvent;
import javax.swing.JTree;

/**
 *
 * @author Администратор
 */
public class ProjectModelView extends javax.swing.JPanel {

    private IProjectModel projectModel;

    private EPrimitiveType selectedType;

    /** Creates new form ProjectModelView */
    public ProjectModelView() {
        initComponents();
    }

    public void setProjectModel(IProjectModel projectModel) {
        this.projectModel = projectModel;
        Initialize();
    }

    public IProjectModel getProjectModel() {
        return this.projectModel;
    }

    private void Initialize() {
        this.projectModelTree1.SetModel(projectModel);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        projectModelTree1 = new UI.Tree.ProjectModelTree();
        documentTabbedPane1 = new UI.DocumentPanel.DocumentTabbedPane();
        jToolBar_Components = new javax.swing.JToolBar();
        jToggleButton_Line = new javax.swing.JToggleButton();
        jToggleButton_Rectangle = new javax.swing.JToggleButton();

        setLayout(new java.awt.BorderLayout());

        projectModelTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                projectModelTree1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(projectModelTree1);

        jSplitPane1.setLeftComponent(jScrollPane1);

        documentTabbedPane1.setAutoscrolls(true);
        documentTabbedPane1.setDoubleBuffered(true);
        jSplitPane1.setRightComponent(documentTabbedPane1);

        add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jToolBar_Components.setOrientation(1);
        jToolBar_Components.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jToggleButton_Line.setText("Линия");
        jToggleButton_Line.setFocusable(false);
        jToggleButton_Line.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton_Line.setPreferredSize(new java.awt.Dimension(93, 25));
        jToggleButton_Line.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar_Components.add(jToggleButton_Line);

        jToggleButton_Rectangle.setText("Прямоугольгник");
        jToggleButton_Rectangle.setFocusable(false);
        jToggleButton_Rectangle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton_Rectangle.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton_Rectangle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton_RectangleActionPerformed(evt);
            }
        });
        jToolBar_Components.add(jToggleButton_Rectangle);

        add(jToolBar_Components, java.awt.BorderLayout.LINE_END);
    }// </editor-fold>//GEN-END:initComponents

    private void projectModelTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_projectModelTree1MouseClicked
        if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount()==2) {
            Object component = ((JTree) evt.getSource()).getSelectionPath().getLastPathComponent();
            if (component instanceof DocumentNode) {
                this.documentTabbedPane1.addDocument(((DocumentNode)component).getDocument());
            }
        }
    }//GEN-LAST:event_projectModelTree1MouseClicked

    private void jToggleButton_RectangleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton_RectangleActionPerformed
        this.selectedType = EPrimitiveType.Rectangle;
}//GEN-LAST:event_jToggleButton_RectangleActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private UI.DocumentPanel.DocumentTabbedPane documentTabbedPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToggleButton jToggleButton_Line;
    private javax.swing.JToggleButton jToggleButton_Rectangle;
    private javax.swing.JToolBar jToolBar_Components;
    private UI.Tree.ProjectModelTree projectModelTree1;
    // End of variables declaration//GEN-END:variables
}
